var getMessageTask=null;
$(function () {

    $("#rootDirectory").click(function () {

        if (event.stopPropagation) {
            // 针对 Mozilla 和 Opera
            event.stopPropagation();
        }else if (window.event) {
            // 针对 IE
            window.event.cancelBubble = true;
        }

        var thisSpan = $(this);
        if ($(this).children('ul').css('display') == 'none') {
            $(this).children("a").children("i").removeClass("menu-icon-right");
            $(this).children("a").children("i").addClass("menu-icon-down");
            $(this).siblings().children("a").children("i").addClass("menu-icon-right");
            $(this).children("ul").slideDown("fast");
            $(this).siblings().children("ul").slideUp("fast");
        } else {
            $(this).children("a").children("i").removeClass("menu-icon-down");
            $(this).children("a").children("i").addClass("menu-icon-right");
            $(this).children("ul").slideUp("fast");
        }
    });
    $("#photoDownload").click(function () {

        if (event.stopPropagation) {
            // 针对 Mozilla 和 Opera
            event.stopPropagation();
        }else if (window.event) {
            // 针对 IE
            window.event.cancelBubble = true;
        }

        $("#projectDetails").children("a").removeClass("checkLi");
        $("#photoDownload").children("a").addClass("checkLi");
        var projectId=$("#projectId").val();
        $("#datamain").attr("src", "/homepage/getphotoListDetails?projectId=" + projectId);
    });
    $("#projectDetails").click(function () {
        event.stopPropagation();
        $("#photoDownload").children("a").removeClass("checkLi");
        $("#projectDetails").children("a").addClass("checkLi");
        var projectId=$("#projectId").val();
        $("#datamain").attr("src", "/homepage/getProjectDetails?projectId=" + projectId);
    });
    init();
});
function init() {
    getMessage();
    setInterval("getMessage()", 30000)
    // $("#datamain").attr("src", "/homepage/findProjectCountByEpsId");
    $(".content-left-submenu ul li").children("ul").slideDown(10);
}
function getMessage() {
    var url="/homepage/findMessage?"+ "newDate=" + (new Date().getTime());;
    $.ajax({
        url: url,
        type: "post",
        dataType: "json",
        success: function (data) {
            if (getMessageTask != null) {
                clearInterval(getMessageTask);
            }

            var messageHtml = "<ul>";
            for (var i = data.length-1; i >=0; i--) {
                messageHtml+="<li style='  overflow: hidden; '>" +
                    "<a style='color:#333;text-decoration : none  ' href='javascript:lookMessage("+data[i].id+");'" +
                    " >"
                    +data[i].infotitle+":"+data[i].infocontent;
                if(data[i].closeMemo !=undefined&&data[i].closeMemo!=null&&data[i].closeMemo !=""){
                    messageHtml+= "<span style='color: red'>"+ data[i].closeMemo+"</span>"
                }

                messageHtml+=   "</a></li>";
            }
            messageHtml += "</ul>";
            $("#message-main").html(messageHtml);
            $("#message-main ul").find('li:first').show();

            getMessageTask=  setInterval("lunbo('#message-main ul','-50px')", 3000)
        }
    })

}
function lunbo(id, height) {
    var ul = $(id);
    var liFirst = ul.find('li:first');
    $(id).animate({top: height}).animate({"top": 0}, 0, function () {
        var clone = liFirst.clone().hide();
        // clone.attr("hidden","hidden");
        $(id).append(clone);
        liFirst.remove();
        ul.find('li:first').show();
    })
}
function lookMessage(id) {
    pageii = layer.open({
        title: "消息详情",
        type: 2,
        fixed: true,
        //shadeClose : true,
        area: ["600px", "550px"],
        content: "/homepage/findMessageDetailsUI?messageId=" +id
    });
}